# _*_coding: UTF-8 _*_
# author:jamesfeng2009
# time:2024/2/14 22:32
# 文心一格  文生图
import erniebot
from aip import AipImageClassify


APP_ID = '51390424'
API_KEY = "Rx3sQKVsroZ16vjOSMG9I0TR"
SECRET_KEY = "EgMkuaObHmDpIkGaQVCjmeANDQG7SY9Z"

erniebot.api_type = 'aistudio'
erniebot.access_token = 'b45ed3a5bb95610b66463d4bfe0ce2a4d2fa3bab'

client = AipImageClassify(APP_ID, API_KEY, SECRET_KEY)

filePath = "pic3.png"

with open(filePath, 'rb') as fp:
    image = fp.read()

options = {"baike_num": 5}

result = client.advancedGeneral(image, options)
print(result)

keyword_list = []

for res in result['result']:
    keyword_list.append(res['keyword'])
keyword_string = ', '.join(keyword_list)
content = '根据' + keyword_string + '写10首两句七言诗'
response = erniebot.ChatCompletion.create(
    model='ernie-bot',
    messages=[{'role': 'user', 'content': f"{content}”"}],
)

data_str = response.result
print(data_str)
